//
//  AlphaViewController.swift
//  Matting
//  Created by JoyWT on 2022/3/8
//  
    

import UIKit
import opencv2
class AlphaViewController: TriMapViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        test()
        // Do any additional setup after loading the view.
        
    }
    
    override func pickedDone() {
        let md = Mat(uiImage: originMaskImage!) //deaplab生成的mask图 ,黑色为前景区域
        //处理背景图片
        let nmd = Mat()
        Core.bitwise_not(src: md, dst: nmd) //对mask图片取反 白色为前景区域

        let trimap = trimap(mask: nmd, shape: .MORPH_CROSS, ksize: Size2i(width: 10, height: 10))
        
        let alpha = alpha(orgin: originalImage!, trimap: trimap.toUIImage())
//        let m = Mat(uiImage: alpha)
//        print(m.dump())
        imageView.image = alpha
        
    }
    func alpha(orgin: UIImage, trimap: UIImage)-> UIImage{
//        let alpha = OpenCVWrapper.infoFlow(UIImage(named: "plant.jpg")!, trimap: UIImage(named: "plant.png")!)
        let alpha = OpenCVWrapper.infoFlow(orgin, trimap: trimap)
        return alpha
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
